<?php

namespace app\index\controller;

use think\Controller;
use think\Validate;
use app\index\model\User;
use think\facade\Session;


class login extends Controller{

    public function index(){

        return $this->fetch();
    }

    public function login(){
        $user = User::get([
            'username' => input('post.user_name'),
            'user_password' => input('post.user_passwd'),
        ]);
        if($user){
            $user->toArray();
            Session::set('user_id',$user->user_id);
            return $this->success('登录成功！','/index/index');
        }else{
            return $this->error('用户名或密码不正确');
        }
    }
}